-- Codea tutorial
Mains = class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
function Mains:setup() 
    back = BackGround()
    cirs = {}
    for i = 1,20 do
        local col = color(math.random() * 255,math.random() * 255,math.random() * 255,50 + math.random() * 100)
        cirs[i] = {math.random() * WIDTH,math.random() * HEIGHT,30 + math.random() * 20,col}
    end
    txt = {y1 = -10,y2 = -10,a = 0}
    t1 = tween(2,txt,{y1=HEIGHT/2},tween.easing.cubicOut)
    t2 = tween(3.5,txt,{y2=HEIGHT/2 - 35},tween.easing.quartOut)
    t3 = tween(4,txt,{a=1},tween.easing.quadOut)
    tween.sequence(t1,t3)
end

function Mains:draw()
    -- This sets a dark background color 
    background(230, 230, 230, 255)
    -- Do your drawing here
    back:draw()
   
    for i,v in ipairs(cirs) do
        fill(v[4]:mix(color(0,0,0,0),txt.a * (0.9 + 0.1 * math.sin(ElapsedTime + v[1]))))
        ellipse(v[1] + math.sin(0.1 * ElapsedTime * (1 + math.fmod(v[2],3)) + v[1]) * (3 + math.fmod(v[1],10)),v[2] + math.cos(0.1 * ElapsedTime * (1 + math.fmod(v[2],3)) + v[1]) * (3 + math.fmod(v[1],10)),v[3])
    end
    
    fill(62, 48, 140, 255)
    font("AmericanTypewriter-Bold")
    fontSize(40)
    text("Codea Tutorials",WIDTH / 2,txt.y1)
    fill(122, 113, 113, 255)
    font("AcademyEngravedLetPlain")
    fontSize(30)
    text("Made with Codea",WIDTH / 2,txt.y2)
end

function Mains:touched(touch)
    back:touched(touch)
end

function Mains:collide(contact)

end

function Mains:keyboars(key) 
    
end

function Mains:orientationChanged(newOrientation)

end